package alibaba.ifelserefactor.demo01.test04;

import alibaba.ifelserefactor.demo01.ShareListener;
import lombok.extern.slf4j.Slf4j;

/**
 * @author ChangLiang
 * @date 2020/4/20
 */
@Slf4j
public class ShareService {

    public void share (ShareItem item, ShareListener listener) {
        if (item == null) {
            if (listener != null) {
                listener.onCallback(ShareListener.STATE_FAIL, "ShareItem 不能为 null");
            }
            return;
        }
        if (listener == null) {
            listener = new ShareListener() {
                @Override
                public void onCallback(int state, String msg) {
                    log.info("DEBUG", "ShareListener is null");
                }
            };
        }
        shareImpl(item, listener);
    }

    private void shareImpl(ShareItem item, ShareListener listener) {
        item.doShare(listener);
    }
}
